{{- if .Values.webhookConfigs.enabled }}
{{- if .Values.modes.mutation.enabled }}
{{ range  .Values.webhookConfigs.mutating }}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
  name: {{ .name }}
webhooks:
  {{ range .webhooks }}
  - name: {{ .name }}
    clientConfig:
      caBundle: {{ $.Values.webhookConfigs.auth.tls.caCertBase64 }}
      service:
        namespace: {{ $.Release.Namespace }}
        name: {{ $.Values.service.name }}
        path: /mutate
        port: {{ $.Values.service.port }}
    rules: {{ .rules | toYaml | nindent 6 }}
    failurePolicy: {{ .failurePolicy | default "Ignore" }}
    matchPolicy: Exact
    namespaceSelector: {{ .namespaceSelector | toYaml | nindent 6 }}
    objectSelector: {{ .objectSelector | toYaml | nindent 6 }}
    sideEffects: None
    timeoutSeconds: {{ .timeoutSeconds | default "5" }}
    admissionReviewVersions:
      - v1beta1
      - v1
    reinvocationPolicy: Never
  {{- end }}
{{- end }}
{{- end }}
{{- end }}